package com.zs4sdk.common;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2018/4/27.
 */

public class Zs4GameSharePreferences {
    private SharedPreferences mSharePreferences = null;
    public Zs4GameSharePreferences(Context context,String sharedPreferencesName){
        mSharePreferences = context.getSharedPreferences(sharedPreferencesName, Context.MODE_MULTI_PROCESS);
    }
    /**
     * 获取String类型
     */
    public String getString(String key) {
        return mSharePreferences.getString(key, "");
    }

    /**
     * 获取String类型
     */
    public String getString(String key, String def) {
        return mSharePreferences.getString(key, def);
    }

    /**
     * 获取float类型
     */
    public float getFloat(String key) {
        return mSharePreferences.getFloat(key, 0f);
    }

    /**
     * 获取float类型
     */
    public float getFloat(String key, float def) {
        return mSharePreferences.getFloat(key, def);
    }

    /**
     * 获取int类型
     */
    public int getInt(String key) {
        return mSharePreferences.getInt(key, 0);
    }

    /**
     * 获取int类型
     */
    public int getInt(String key, int def) {
        return mSharePreferences.getInt(key, def);
    }

    /**
     * 获取long类型
     */
    public long getLong(String key) {
        return mSharePreferences.getLong(key, 0);
    }

    /**
     * 获取long类型, 可设置初始值
     */
    public long getLong(String key, Long defaultVal) {
        return mSharePreferences.getLong(key, defaultVal);
    }

    /**
     * 获取long类型
     */
    public long getLong(String key, long def) {
        return mSharePreferences.getLong(key, def);
    }

    /**
     * 获取boolean类型
     */
    public boolean getBoolean(String key) {
        return mSharePreferences.getBoolean(key, false);
    }

    /**
     * 获取boolean类型
     */
    public boolean getBoolean(String key, boolean def) {
        return mSharePreferences.getBoolean(key, def);
    }

    /**
     * 设置String类型
     */
    public void putString(String key, String value) {
        SharedPreferences.Editor ed = mSharePreferences.edit();
        ed.putString(key, value);
        ed.commit();
    }

    /**
     * 设置Int类型
     */
    public void putInt(String key, int value) {
        SharedPreferences.Editor ed = mSharePreferences.edit();
        ed.putInt(key, value);
        ed.commit();
    }

    /**
     * 设置Long类型
     */
    public void putFloat(String key, float value) {
        SharedPreferences.Editor ed = mSharePreferences.edit();
        ed.putFloat(key, value);
        ed.commit();
    }

    /**
     * 设置Long类型
     */
    public void putLong(String key, long value) {
        SharedPreferences.Editor ed = mSharePreferences.edit();
        ed.putLong(key, value);
        ed.commit();
    }

    /**
     *  设置Boolean类型
     */
    public void putBoolean(String key, boolean value) {
        SharedPreferences.Editor ed = mSharePreferences.edit();
        ed.putBoolean(key, value);
        ed.commit();
    }

    public void clear(){
        SharedPreferences.Editor ed = mSharePreferences.edit();
        ed.clear();
        ed.commit();
    }
}
